<template>
<div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="订单编号" prop="orderNum">
        <el-input
          v-model="queryParams.orderNum"
          placeholder="请输入商品订单"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="completeStatus">
        <el-select
          v-model="queryParams.completeStatus"
          placeholder="查看订单状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="ordertable">    
    <table class="tablee">
        <thead>
            <th class="thone" style="width:500px">订单详情</th>
            <th class="thone">成交单价</th>
            <th class="thone">购买数量</th>
            <th class="thone">实付金额</th>
            <th class="thone">支付方式</th>
            <th class="thone">付款状态</th>
            <th class="thone">订单状态</th>
            <th class="thone">操作</th>
        </thead>
        <tbody v-for="(good,index) in goods" :key="index">
            <tr class="sep-row"><td colspan="8"></td></tr>
            <tr class="tr-th">
                <td colspan="8" style="border:solid 1px  #dfdfdf;">
                    <div style="padding:5px">
                        <span>订单编号：{{good.orderNum}}</span>
                        <span style="margin-left:30px">下单时间：{{good.creatTime}}</span>
                    </div>
                </td>
            </tr>
            <tr class="tr-bd">
                <td class="tdtd">
                    <div>
                     <img :src="good.mainImgUrl" 
                     style="height:120px;width:120px;border: 1px solid #efefef;margin: 5px 14px;float:left" />
                         <div style="float:left;margin:20px;"><span>{{good.goodsName}}</span></div>
                    </div>
                </td>
                <td rowspan="1" class="tdtd">
                    <div><span>¥{{(good.goodsPrice/100).toFixed(2)}}</span></div>
                </td>
                <td rowspan="1" class="tdtd">
                    <div><span>{{good.goodsCount}}</span></div>
                </td>
                <td rowspan="1" class="tdtd">
                    <div><span style="color:red;">¥{{(good.totalPay/100).toFixed(2)}}</span></div>
                </td>
                <td rowspan="1" class="tdtd">
                    <div><span>{{good.payWay}}</span></div>
                </td>
                <td rowspan="1" class="tdtd">
                    <div><span>{{good.orderStatus == '0' ? '未支付' :good.orderStatus == '1' ? '已支付' : '已过期'}}</span></div>
                </td>
                <td rowspan="1" class="tdtd">
                    <div><span>{{good.completeStatus == '0' ? '未完成' : '已完成'}}</span></div>
                </td>
                <td rowspan="1" class="tdtd" style="border-right:solid 1px  #dfdfdf;">
                    <el-button type="danger" v-if="good.completeStatus == '0'" plain @click="Done(good.orderId)">确认收货</el-button>
                    <el-button type="success" v-if="good.completeStatus == '1'" plain disabled>已收货</el-button>
                </td>
            </tr>
        </tbody>
    </table>
    <!-- 分页 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>
</div>
</template>

<script>
import { confirmGoods, getBuy,  } from '@/api/shop/order'

export default {
    name:"Order",
    inject:['reload'],//注入刷新当前页面的依赖
    data() {
        return {
        goodsList: [],
        goodsOptions: [],
        statusOptions: [],
        goods: {},
        showSearch: true,
        total: 0,
        loading: true,

       // 查询参数
        queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsName: undefined,
        orderNum: undefined,
        completeStatus: undefined,
      },
        }
    },
    created() {
        console.log('获取订单')
        this.getList()
        this.getDicts('shop_order_status').then(response => {
            this.goodsOptions = response.data
            })
        this.getDicts('shop_order_complete').then(response => {
            this.statusOptions = response.data
            })
    },
    methods: {
    getList() {
      getBuy( this.queryParams ).then(response => {
          this.goodsList = response.rows
          this.goods = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    // 搜索
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 表单重置
    reset() {},
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    Done(orderId) {
        console.log("确认收货")
        confirmGoods(orderId).then(response => {
          if (response.code === 200) {
          this.msgSuccess('收货成功')
          this.reload()
        }
        })
    },
    },
}
</script>

<style lang="less" scoped>
.tr-th {
    background: #f1f4f8;
    height: 31px;
    line-height: 31px;
    color: rgb(103, 104, 107);
    overflow: hidden;
}
.thone {
    width:150px;
    height: 35px;
    background: #e6eaee;
    color: rgb(90, 92, 104);
    overflow: hidden;
}
.tr-bd {
    text-align: center;
    border: 1px solid #838383;
}
.sep-row {
    height: 20px;
}
.tdtd {
    border-bottom:solid 1px  #dfdfdf;
    border-left:solid 1px  #dfdfdf;
}
</style>
